package com.homeparking.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.homeparking.common.annotation.Log;
import com.homeparking.common.core.controller.BaseController;
import com.homeparking.common.core.domain.AjaxResult;
import com.homeparking.common.enums.BusinessType;
import com.homeparking.manage.domain.ManageArticle;
import com.homeparking.manage.service.IManageArticleService;
import com.homeparking.common.utils.poi.ExcelUtil;
import com.homeparking.common.core.page.TableDataInfo;

/**
 * 系统文章Controller
 * 
 * @author liuyangyang
 * @date 2025-10-29
 */
@RestController
@RequestMapping("/manage/manage_article")
public class ManageArticleController extends BaseController
{
    @Autowired
    private IManageArticleService manageArticleService;

    /**
     * 查询系统文章列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ManageArticle manageArticle)
    {
        startPage();
        List<ManageArticle> list = manageArticleService.selectManageArticleList(manageArticle);
        return getDataTable(list);
    }

    /**
     * 导出系统文章列表
     */
    @PreAuthorize("@ss.hasPermi('manage:manage_article:export')")
    @Log(title = "系统文章", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ManageArticle manageArticle)
    {
        List<ManageArticle> list = manageArticleService.selectManageArticleList(manageArticle);
        ExcelUtil<ManageArticle> util = new ExcelUtil<ManageArticle>(ManageArticle.class);
        util.exportExcel(response, list, "系统文章数据");
    }

    /**
     * 获取系统文章详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:manage_article:query')")
    @GetMapping(value = "/{articleId}")
    public AjaxResult getInfo(@PathVariable("articleId") String articleId)
    {
        return success(manageArticleService.selectManageArticleByArticleId(articleId));
    }

    /**
     * 新增系统文章
     */
    @PreAuthorize("@ss.hasPermi('manage:manage_article:add')")
    @Log(title = "系统文章", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ManageArticle manageArticle)
    {
        return toAjax(manageArticleService.insertManageArticle(manageArticle));
    }

    /**
     * 修改系统文章
     */
    @PreAuthorize("@ss.hasPermi('manage:manage_article:edit')")
    @Log(title = "系统文章", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ManageArticle manageArticle)
    {
        return toAjax(manageArticleService.updateManageArticle(manageArticle));
    }

    /**
     * 删除系统文章
     */
    @PreAuthorize("@ss.hasPermi('manage:manage_article:remove')")
    @Log(title = "系统文章", businessType = BusinessType.DELETE)
	@DeleteMapping("/{articleIds}")
    public AjaxResult remove(@PathVariable String[] articleIds)
    {
        return toAjax(manageArticleService.deleteManageArticleByArticleIds(articleIds));
    }
}
